package com.wbdgj.ui.near;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.services.geocoder.GeocodeAddress;
import com.amap.api.services.geocoder.GeocodeQuery;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.google.gson.internal.LinkedTreeMap;
import com.igexin.sdk.PushManager;
import com.wbdgj.R;
import com.wbdgj.adapter.NewsAdapter;
import com.wbdgj.adapter.SxAdapter;
import com.wbdgj.adapter.WbAdapter;
import com.wbdgj.adapter.YueAdapter;
import com.wbdgj.base.BaseApplication;
import com.wbdgj.base.BaseFragment;
import com.wbdgj.base.BaseWhiteActivity;
import com.wbdgj.base.BaseWhiteFragment;
import com.wbdgj.http.HttpAdapter;
import com.wbdgj.http.OnNoResponseListener;
import com.wbdgj.http.OnResponseListener;
import com.wbdgj.model.ResultObjectModel;
import com.wbdgj.model.SxModel;
import com.wbdgj.ui.booking.BookingActivity;
import com.wbdgj.ui.branch.BranchDetailActivity;
import com.wbdgj.ui.home.ExampleActivity;
import com.wbdgj.ui.home.ExampleListActivity;
import com.wbdgj.ui.home.LoactionActivity;
import com.wbdgj.ui.home.NewsActivity;
import com.wbdgj.ui.home.NewsAllActivity;
import com.wbdgj.ui.home.SearchActivity;
import com.wbdgj.ui.home.WbDetailActivity;
import com.wbdgj.ui.login.LoginActivity;
import com.wbdgj.ui.news.NewsDetailActivity;
import com.wbdgj.ui.store.StoreCofeActivity;
import com.wbdgj.ui.store.StoreHotelActivity;
import com.wbdgj.utils.CommonUtils;
import com.wbdgj.utils.SpKeyUtils;
import com.wbdgj.utils.ToastUtils;
import com.wbdgj.utils.dialog.LoadingDialog;
import com.wbdgj.utils.refresh.PullListView;
import com.wbdgj.utils.refresh.PullToRefreshLayout;
import com.wbdgj.views.DropDownMenuView;
import com.zaaach.citypicker.CityPickerActivity;
import com.zaaach.citypicker.model.LocateState;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import retrofit2.Call;

/**
 * Created by Administrator on 2018/5/2.
 */

public class NearFragment extends BaseWhiteFragment {

    private Context context;

    //声明AMapLocationClient类对象
    public AMapLocationClient mLocationClient = null;


    //声明AMapLocationClientOption对象
    public AMapLocationClientOption mLocationOption = null;

    private String COORDSX, COORDSY, PROVINCE, CITY, DISTRICT;

    @BindView(R.id.demo_listview)
    PullListView myPullListView;
    @BindView(R.id.pullToRefreshLayout)
    PullToRefreshLayout myPullToRefreshLayout;
    private int page = 1;
    private int totalPage;
    private ArrayList<LinkedTreeMap> linkedTreeMapList;
    private WbAdapter wbAdapter;
    private DecimalFormat decimalFormat;

    @BindView(R.id.tv_leftTitle)
    TextView tv_leftTitle;

    @BindView(R.id.dropDownMenu)
    DropDownMenuView dropDownMenu;

    @BindView(R.id.sxList)
    ListView sxList;

    private ArrayList<SxModel> sxModels;
    private SxAdapter sxAdapter;

    //全局的jsonObject
    private JSONObject jsonObject;//把全国的省市区的信息以json的格式保存，解析完成后赋值为null
    private String[] allProv;//所有的省

    private int isSxTxt = 0;
    private LoadingDialog dialog;
    //省市区的集合
    private ArrayList<SxModel>  shiqModels;
    private ArrayList<SxModel>  jlModels;
    private ArrayList<SxModel>  znModels;
    private Map<String, String[]> cityMap = new HashMap<String, String[]>();//key:省p---value:市n  value是一个集合
    private Map<String, ArrayList<SxModel>> areaMap = new HashMap<String, ArrayList<SxModel>>();//key:市n---value:区s    区也是一个集合
    private String qyTxt = "";
    private String jlTxt = "";
    private String znTxt = "3";

    @BindView(R.id.qyTxt)
    TextView qyTxtLay;
    @BindView(R.id.jlTxt)
    TextView jlTxtLay;
    @BindView(R.id.znTxt)
    TextView znTxtLay;
    @BindView(R.id.pointXx)
    ImageView pointXx;

    @Override
    protected int getLayout() {
        return R.layout.ui_near;
    }

    @Override
    protected void onInit() {
        context = getActivity();
        dialog = new LoadingDialog(context);
        dialog.setText("正在定位中...");
        initJsonData();//初始化json数据
        initDatas();//初始化省市区数据
        initLocation();
        decimalFormat = new DecimalFormat("###################.###########");
        myPullToRefreshLayout.setOnRefreshListener(new PullToRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh(PullToRefreshLayout pullToRefreshLayout) {
                pullToRefreshLayout.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        page = 1;
                        queryAll(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.PROVINCE), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CITY), qyTxt, jlTxt, znTxt);
                        myPullToRefreshLayout.refreshFinish(true);
                        ToastUtils.toastShort("刷新成功");
                    }
                }, 1000);
            }

            @Override
            public void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {
                page = page + 1;
                if (page > totalPage){
                    ToastUtils.toastShort("已无更多");
                }else{
                    queryAll(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.PROVINCE), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CITY), qyTxt, jlTxt, znTxt);
                }
                myPullToRefreshLayout.loadMoreFinish(true);
            }
        });
        myPullListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (!wbAdapter.hasNoData){
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.HOTEL_ID, decimalFormat.format(wbAdapter.getItem(i).get("BRANCH_ID")));
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.HOTEL_NAME, wbAdapter.getItem(i).get("NAME")+"");
                    if(wbAdapter.getItem(i).containsKey("BRANCH_ATTRIBUTE")){
                        if(decimalFormat.format(wbAdapter.getItem(i).get("BRANCH_ATTRIBUTE")).equals("0")){
                            startActivity(new Intent(context, StoreCofeActivity.class));
                        }else if(decimalFormat.format(wbAdapter.getItem(i).get("BRANCH_ATTRIBUTE")).equals("1")){
                            startActivity(new Intent(context, BookingActivity.class));
                        }else{
                            startActivity(new Intent(context, StoreHotelActivity.class));
                        }
                    }else{
                        startActivity(new Intent(context, StoreCofeActivity.class));
                    }



//                    if(decimalFormat.format(wbAdapter.getItem(i).get("BRANCH_ATTRIBUTE")).equals("0")){
//                        BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.HOTEL_ID, decimalFormat.format(wbAdapter.getItem(i).get("BRANCH_ID")));
//                        BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.HOTEL_NAME, wbAdapter.getItem(i).get("NAME")+"");
//                        startActivity(new Intent(context, StoreCofeActivity.class));
//                    }else{
//                        startActivity(new Intent(context, BranchDetailActivity.class).putExtra("id", decimalFormat.format(wbAdapter.getItem(i).get("BRANCH_ID"))).putExtra("DISTANCE", decimalFormat.format(wbAdapter.getItem(i).get("DISTANCE"))));
//                    }
                }

            }
        });

        sxList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                dropDownMenu.close();
                if (!sxAdapter.hasNoData){
                    if (isSxTxt == 1){
                        qyTxt = shiqModels.get(i).getTitle();
                        qyTxtLay.setText(qyTxt);
                        page = 1;
                        queryAll(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.PROVINCE), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CITY), qyTxt, jlTxt, znTxt);
                    }else if (isSxTxt == 2){
                        if (jlModels.get(i).getIsChoice().equals("1")){
                            jlTxt = "";
                            page = 1;
                            jlTxtLay.setText("距离");
                            queryAll(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.PROVINCE), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CITY), qyTxt, jlTxt, znTxt);
                        }else{
                            page = 1;
                            jlTxtLay.setText(jlModels.get(i).getTitle());
                            jlTxt = jlModels.get(i).getTitle().replace("m", "");
                            queryAll(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.PROVINCE), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CITY), qyTxt, jlTxt, znTxt);
                        }
                    }else if (isSxTxt == 3){
                        if (znModels.get(i).getIsChoice().equals("1")){
                            znTxt = "3";
                            page = 1;
                            znTxtLay.setText("智能");
                            queryAll(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.PROVINCE), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CITY), qyTxt, jlTxt, znTxt);
                        }else{
                            znTxt = "2";
                            page = 1;
                            znTxtLay.setText(znModels.get(i).getTitle());
                            queryAll(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.PROVINCE), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CITY), qyTxt, jlTxt, znTxt);
                        }
                    }
                }

            }
        });
    }

    @OnClick({R.id.tv_rightImg, R.id.tv_searchLay, R.id.tv_leftTitle, R.id.qyLay, R.id.jlLay, R.id.znLay})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_rightImg:
                launch(NewsAllActivity.class);
                break;
            case R.id.qyLay:
                if(!dropDownMenu.isOpen()){
                    shiqModels = new ArrayList<>();
                    shiqModels = areaMap.get(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CITY));
                    sxAdapter = new SxAdapter(context, shiqModels);
                    sxList.setAdapter(sxAdapter);
                    dropDownMenu.open();
                    isSxTxt = 1;
                }else{
                    qyTxtLay.setText("区域");
                    dropDownMenu.close();
                    qyTxt = "";
                    queryAll(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.PROVINCE), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CITY), qyTxt, jlTxt, znTxt);
                }
                break;
            case R.id.jlLay:

                if(!dropDownMenu.isOpen()){
                    jlModels = new ArrayList<>();
                    jlModels.add(new SxModel("1000m","0", "0"));
                    jlModels.add(new SxModel("2000m","1", "0"));
                    jlModels.add(new SxModel("3000m","2", "0"));
                    jlModels.add(new SxModel("4000m","3", "0"));
                    jlModels.add(new SxModel("5000m","4", "0"));
                    jlModels.add(new SxModel("不限","5", "1"));
                    sxAdapter = new SxAdapter(context, jlModels);
                    sxList.setAdapter(sxAdapter);
                    dropDownMenu.open();

                    isSxTxt = 2;
                }else{
                    jlTxtLay.setText("距离");
                    dropDownMenu.close();
                    jlTxt = "";
                    queryAll(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.PROVINCE), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CITY), qyTxt, jlTxt, znTxt);
                }
                break;
            case R.id.znLay:

                if(!dropDownMenu.isOpen()){
                    znModels = new ArrayList<>();
                    znModels.add(new SxModel("关注度","0", "0"));
                    znModels.add(new SxModel("不限","1", "1"));
                    sxAdapter = new SxAdapter(context, znModels);
                    sxList.setAdapter(sxAdapter);
                    dropDownMenu.open();
                    isSxTxt = 3;
                }else{
                    znTxtLay.setText("智能");
                    dropDownMenu.close();
                    znTxt = "2";
                    queryAll(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.PROVINCE), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CITY), qyTxt, jlTxt, znTxt);
                }
                break;
            case R.id.tv_searchLay:
                startActivity(new Intent(context, SearchActivity.class));
                break;
            case R.id.tv_leftTitle:
                startActivityForResult(new Intent(context, LoactionActivity.class),
                        233);
                break;

        }
    }

    @Override
    public void fetchData() {

    }

    @Override
    public void onResume() {
        super.onResume();
        if (!BaseApplication.getInstance().isFirstEnter()){
            tv_leftTitle.setText(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CITY));
        }
        appmbmsgcnt();
    }

    //声明定位回调监听器
    public AMapLocationListener mLocationListener = new AMapLocationListener() {
        @Override
        public void onLocationChanged(AMapLocation amapLocation) {
            if (amapLocation != null) {
                if (amapLocation.getErrorCode() == 0) {
                    mLocationClient.stopLocation();
                    Log.e("zp", "城市："+amapLocation.getCity());
                    Log.e("zp", "城市："+amapLocation.getLatitude());
                    Log.e("zp", "城市："+amapLocation.getLongitude());
                    //可在其中解析amapLocation获取相应内容。
                    COORDSX =  "" + CommonUtils.gaoDeToBaidu(amapLocation.getLatitude(), amapLocation.getLongitude())[0];
                    COORDSY =  "" + CommonUtils.gaoDeToBaidu(amapLocation.getLatitude(), amapLocation.getLongitude())[1];
                    PROVINCE= amapLocation.getProvince().replaceAll("", "");
                    CITY = amapLocation.getCity().replaceAll("", "");
                    DISTRICT = amapLocation.getDistrict().replaceAll("", "");
                } else {
                    //定位失败时，可通过ErrCode（错误码）信息来确定失败的原因，errInfo是错误信息，详见错误码表。
                    Log.e("AmapError", "location Error, ErrCode:"
                            + amapLocation.getErrorCode() + ", errInfo:"
                            + amapLocation.getErrorInfo());
                    COORDSX =  "0" ;
                    COORDSY =  "0" ;
                }
                dialog.dismiss();
                queryAll(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.PROVINCE), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CITY), qyTxt, jlTxt, znTxt);
            }
        }
    };


    private void initLocation() {
        dialog.show();
        //初始化定位
        mLocationClient = new AMapLocationClient(context);
        //设置定位回调监听
        mLocationClient.setLocationListener(mLocationListener);

        //初始化AMapLocationClientOption对象
        mLocationOption = new AMapLocationClientOption();

        //设置定位模式为AMapLocationMode.Hight_Accuracy，高精度模式。
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        //获取一次定位结果：
        //该方法默认为false。
        mLocationOption.setOnceLocation(true);

        //获取最近3s内精度最高的一次定位结果：

        //设置setOnceLocationLatest(boolean b)接口为true，启动定位时SDK会返回最近3s内精度最高的一次定位结果。如果设置其为true，setOnceLocation(boolean b)接口也会被设置为true，反之不会，默认为false。
        mLocationOption.setOnceLocationLatest(true);


        //设置定位间隔,单位毫秒,默认为2000ms，最低1000ms。
        mLocationOption.setInterval(1000);

        //设置是否返回地址信息（默认返回地址信息）
        mLocationOption.setNeedAddress(true);

        //单位是毫秒，默认30000毫秒，建议超时时间不要低于8000毫秒。
        mLocationOption.setHttpTimeOut(20000);

        //给定位客户端对象设置定位参数
        mLocationClient.setLocationOption(mLocationOption);
        //启动定位
        mLocationClient.startLocation();
    }

    private void queryAll(String PROVINCE, String CITY, String DISTRICT, String DISTANCE, String AI) {
        Call<ResultObjectModel> call = HttpAdapter.getSerives().queryAll(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.TOKEN), COORDSX, COORDSY, "10", page+"",
                PROVINCE, CITY, DISTRICT, "", DISTANCE, AI, "");
        call.enqueue(new OnResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
                    DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                    LinkedTreeMap pageLinkedTreeMap = (com.google.gson.internal.LinkedTreeMap) linkedTreeMap.get("page");
                    totalPage = Integer.parseInt(decimalFormat.format(pageLinkedTreeMap.get("totalPage")));
                    linkedTreeMapList = new ArrayList<>();
                    linkedTreeMapList = (ArrayList<LinkedTreeMap>) linkedTreeMap.get("branchList");
                    if (page == 1){
                        wbAdapter = new WbAdapter(context, linkedTreeMapList);
                        myPullListView.setAdapter(wbAdapter);

                    }else{
                        wbAdapter.loadMoreListView(linkedTreeMapList);
                        wbAdapter.notifyDataSetChanged();
                    }
                }else if (userModelBaseResultModel.getResultCode().equals("1111")){
                    ToastUtils.toastShort("账号没有登录或在其它地方登录");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.TOKEN, "");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.IS_AUTO_LOGIN, "2");
                    PushManager.getInstance().unBindAlias(context, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.LOGIN_PHONE), false, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CID));
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }else{
                    ToastUtils.toastShort(userModelBaseResultModel.getResultMsg());
                }
            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 233 && resultCode == -1) {
            if (data != null) {
                String city = data.getStringExtra(CityPickerActivity.KEY_PICKED_CITY);
                BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.CITY, city);
                getLatlon(city);
                tv_leftTitle.setText(city);
            }
        }
    }

    /**
     * 从assert文件夹中获取json数据
     */
    private void initJsonData() {
        try {
            StringBuffer sb = new StringBuffer();
            InputStream is = context.getAssets().open("city.json");//打开json数据
            byte[] by = new byte[is.available()];//转字节
            int len = -1;
            while ((len = is.read(by)) != -1) {
                sb.append(new String(by, 0, len, "gb2312"));//根据字节长度设置编码
            }
            is.close();//关闭流
            jsonObject = new JSONObject(sb.toString());//为json赋值
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //初始化省市区数据
    private void initDatas() {
        try {
            JSONArray jsonArray = jsonObject.getJSONArray("citylist");//获取整个json数据
            allProv = new String[jsonArray.length()];//封装数据
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonP = jsonArray.getJSONObject(i);//jsonArray转jsonObject
                String provStr = jsonP.getString("p");//获取所有的省
                allProv[i] = provStr;//封装所有的省
                JSONArray jsonCity = null;

                try {
                    jsonCity = jsonP.getJSONArray("c");//在所有的省中取出所有的市，转jsonArray
                } catch (Exception e) {
                    continue;
                }
                //所有的市
                String[] allCity = new String[jsonCity.length()];//所有市的长度
                for (int c = 0; c < jsonCity.length(); c++) {
                    JSONObject jsonCy = jsonCity.getJSONObject(c);//转jsonObject
                    String cityStr = jsonCy.getString("n");//取出所有的市
                    allCity[c] = cityStr;//封装市集合

                    JSONArray jsonArea = null;
                    try {
                        jsonArea = jsonCy.getJSONArray("a");//在从所有的市里面取出所有的区,转jsonArray
                    } catch (Exception e) {
                        continue;
                    }
                    ArrayList<SxModel> shiq = new ArrayList<>();
                    String[] allArea = new String[jsonArea.length()];//所有的区
                    for (int a = 0; a < jsonArea.length(); a++) {
                        JSONObject jsonAa = jsonArea.getJSONObject(a);
                        String areaStr = jsonAa.getString("s");//获取所有的区
                        allArea[a] = areaStr;//封装起来
                        shiq.add(new SxModel(areaStr, a+"", "0"));
                    }
                    areaMap.put(cityStr, shiq);//某个市取出所有的区集合
                }
                cityMap.put(provStr, allCity);//某个省取出所有的市,
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        jsonObject = null;//清空所有的数据
    }

    private void getLatlon(String cityName){

        GeocodeSearch geocodeSearch=new GeocodeSearch(context);
        geocodeSearch.setOnGeocodeSearchListener(new GeocodeSearch.OnGeocodeSearchListener() {
            @Override
            public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {

            }

            @Override
            public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {

                if (i==1000){
                    if (geocodeResult!=null && geocodeResult.getGeocodeAddressList()!=null &&
                            geocodeResult.getGeocodeAddressList().size()>0){

                        GeocodeAddress geocodeAddress = geocodeResult.getGeocodeAddressList().get(0);
                        double latitude = geocodeAddress.getLatLonPoint().getLatitude();//纬度
                        double longititude = geocodeAddress.getLatLonPoint().getLongitude();//经度
                        String adcode= geocodeAddress.getAdcode();//区域编码
                        Log.e("地理编码", geocodeAddress.getAdcode()+"");
                        Log.e("纬度latitude",latitude+"");
                        Log.e("经度longititude",longititude+"");
                        Log.e("地区",geocodeAddress.getAdcode());
                        Log.e("地区",geocodeAddress.getCity());
                        Log.e("地区",geocodeAddress.getProvince());
                        BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.PROVINCE, geocodeAddress.getProvince());
                        queryAll(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.PROVINCE), BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CITY), qyTxt, jlTxt, znTxt);
                    }else {
                        ToastUtils.toastShort("地址名出错");
                    }
                }
            }
        });
        GeocodeQuery geocodeQuery=new GeocodeQuery(cityName.trim(),"29");
        geocodeSearch.getFromLocationNameAsyn(geocodeQuery);
    }


    private void appmbmsgcnt() {
        Call<ResultObjectModel> call01 = HttpAdapter.getSerives().appmbmsgcnt(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.TOKEN));
        call01.enqueue(new OnNoResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
                    if (decimalFormat.format(linkedTreeMap.get("CNT")).equals("0")){
                        pointXx.setVisibility(View.GONE);
                    }else{
                        pointXx.setVisibility(View.VISIBLE);
                    }
                }else if (userModelBaseResultModel.getResultCode().equals("1111")){
                    ToastUtils.toastShort("账号没有登录或在其它地方登录");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.TOKEN, "");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.IS_AUTO_LOGIN, "2");
                    PushManager.getInstance().unBindAlias(context, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.LOGIN_PHONE), false, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CID));
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }
            }
        });
    }
}
